# -*- coding: utf-8 -*-
"""
Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community
Edition) available.
Copyright (C) 2017-2020 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""

from django.db import models

# Create your models here.

import settings


class MissionStatus:
    EXPIRED = 0
    EFFECT = 1
    ACCEPT = 2
    CHECK = 3
    FINISH = 4
    CANCEL = 5


class Offline(models.Model):
    STATUS = [
        (MissionStatus.EXPIRED, "已过期"),
        (MissionStatus.EFFECT, "生效中"),
        (MissionStatus.ACCEPT, "已接单"),
        (MissionStatus.CHECK, "待审核"),
        (MissionStatus.FINISH, "已完成"),
        (MissionStatus.CANCEL, "已取消"),
    ]
    MISSION_TYPE_LIST = [(0, '其他'), (1, '取外卖'), (2, '取快递'), (3, "跑腿"), (4, "打印")]
    belonging_user = models.ForeignKey(settings.AUTH_USER_MODEL, models.CASCADE, verbose_name="发布人")
    create_time = models.DateTimeField(verbose_name="发布时间", auto_now_add=True)
    mission_type = models.IntegerField(verbose_name="任务类型", choices=MISSION_TYPE_LIST)
    mission_require = models.TextField(verbose_name="任务需求")
    effect_time = models.DateTimeField(verbose_name="截止时间")
    mission_salary = models.FloatField(verbose_name="任务薪水", default=0)
    mission_status = models.IntegerField(verbose_name="任务状态", choices=STATUS, default=MissionStatus.EFFECT)
    mission_phone = models.CharField(verbose_name="联系方式", max_length=20)
    mission_remarks = models.TextField(verbose_name="任务备注", null=True, blank=True)
    update_time = models.DateTimeField(verbose_name="最后修改时间", auto_now=True)

    class Meta:
        verbose_name = "跑腿任务"
        verbose_name_plural = verbose_name
        ordering = ["-create_time"]
        db_table = "compus_offline_mission"

    def __str__(self):
        return self.belonging_user.username + self.get_mission_type_display()


class Sex:
    FEMALE = 0
    MALE = 1


class UserCenter(models.Model):
    UserSex = [
        (Sex.FEMALE, "女"),
        (Sex.MALE, "男"),
    ]
    compus_user = models.ForeignKey(settings.AUTH_USER_MODEL, models.CASCADE, verbose_name="用户")
    user_sex = models.SmallIntegerField(verbose_name="用户性别", choices=UserSex, default=Sex.MALE, null=True, blank=True)
    user_phone = models.CharField(verbose_name="用户电话", max_length=20, null=True, blank=True)
    user_remarks = models.TextField(verbose_name="用户备注", null=True, blank=True)
    user_email = models.CharField(verbose_name="用户邮箱", max_length=40, null=True, blank=True)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)

    class Meta:
        verbose_name = "用户信息表"
        verbose_name_plural = verbose_name
        ordering = ["-create_time"]
        db_table = "compus_user_center"

    def __str__(self):
        return self.compus_user.username


class AcceptMission(models.Model):
    accept_mission = models.ForeignKey(Offline, models.CASCADE, verbose_name="接受订单号")
    accept_user = models.ForeignKey(UserCenter, models.CASCADE, verbose_name="接单人")
    create_time = models.DateTimeField(verbose_name="接单时间", auto_now_add=True)
    update_time = models.DateTimeField(verbose_name="状态更新时间", auto_now=True)
    attachment_name = models.CharField(verbose_name="附件名称", max_length=32, null=True, blank=True)
    attachment_url = models.TextField(verbose_name="附件URL", null=True, blank=True)
    remark = models.TextField(verbose_name="完成情况", null=True, blank=True)
    comment = models.TextField(verbose_name="评价", null=True, blank=True)

    class Meta:
        verbose_name = "接单表"
        verbose_name_plural = verbose_name
        ordering = ["-create_time"]
        db_table = "compus_accept_mission"

    def __str__(self):
        return self.accept_mission.get_mission_status_display()

